﻿using System;
using System.Data;
using System.Text;
using System.Web.UI.HtmlControls;

namespace LKCMS.Web
{
    public partial class NormalType : System.Web.UI.Page
    {
        public int Id;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                if (!int.TryParse(Request.Params["id"] as string, out this.Id))
                {
                    JscriptMsg(300, 120, "错误提示", "<div style=\" padding:5px 5px 5px 5px; text-align:left;line-height:30px;\"><b>亲爱访友：</b><br/>&nbsp;&nbsp&nbsp;&nbsp;<span style=\"color:#FBF204;\">您要打开的信息不存在或参数不正确。<span/><br/></div><div style=\"text-align:center;\"><a href=\"Index.aspx\">跳转到首页</a></div>");
                    return;
                }
                else
                {
                    Bind(this.Id);
                }
            }
        }
        private void BindMeta(string classname)
        {
            LKCMS.Model.WebSet webset = new LKCMS.BLL.WebSet().loadConfig(LKCMS.Common.Utils.GetXmlMapPath("Configpath"));

            Page.Title = classname + "_" + webset.WebKeywords;


            //Encode/Content type
            HtmlMeta encode = new HtmlMeta();
            encode.HttpEquiv = "Content-Type";
            encode.Content = "text/html; charset=utf-8";
            Page.Header.Controls.Add(encode);

            //Language
            HtmlMeta lang = new HtmlMeta();
            lang.HttpEquiv = "Content-Language";
            lang.Content = "zh-cn";
            Page.Header.Controls.Add(lang);

            //Description
            HtmlMeta desc = new HtmlMeta();
            desc.Name = "Description";
            desc.Content = webset.WebDescription;
            Page.Header.Controls.Add(desc);

            //Keyword
            HtmlMeta keywords = new HtmlMeta();
            keywords.Name = "keywords";
            keywords.Content = webset.WebKeywords;
            Page.Header.Controls.Add(keywords);

        }
        /// <summary>
        /// 遮罩提示窗口
        /// </summary>
        /// <param name="w">宽度</param>
        /// <param name="h">高度</param>
        /// <param name="msgtitle">窗口标题</param>
        /// <param name="msgbox">提示文字</param>
        /// <param name="url">返回地址</param>
        /// <param name="msgcss">CSS样式</param>
        private void JscriptMsg(int w, int h, string msgtitle, string msgbox)
        {
            string msbox = "";
            msbox += "<script src=\"Js/jsmsg.js\" type=\"text/javascript\"></script>\n";
            msbox += "<script type=\"text/javascript\">\n";

            msbox += "alertWin('" + msgtitle + "','" + msgbox + "'," + w + "," + h + ");";
            msbox += "</script>";
            this.Literal2.Text = msbox;
            //  Msg.Text = msbox;
            // Response.End();
        }

        private void Bind(int id)
        {
            StringBuilder sb = new StringBuilder();
            StringBuilder sb1 = new StringBuilder();
            StringBuilder sb2 = new StringBuilder();
            LKCMS.BLL.Channel bll = new LKCMS.BLL.Channel();
            LKCMS.BLL.Pictures pll = new LKCMS.BLL.Pictures();
            LKCMS.BLL.Article all = new LKCMS.BLL.Article();
            LKCMS.Model.Channel model = bll.GetModel(id);

            string typename = model.Title;
            BindMeta(typename);
            DataTable dt = bll.GetListNew(" ParentId=" + id);
            string urladd = string.Empty;
            DataTable dtzx = new DataTable();
            DataTable dtrd = new DataTable();
            if (dt.Rows.Count > 0)
            {
                #region MyRegion

                //    sb.Append("<div class=\"type_menu_dao\">");
                //    sb.Append("<div style=\"background:url(images/daohang.jpg) no-repeat; width:280px; height:30px; margin-left:3px; line-height:30px; text-align:center; color:#FBF204; font-size:14px;\">");
                //    sb.Append("<b>" + typename + "</b></div>");
                //    sb.Append("<ul>");
                //    foreach (DataRow dr in dt.Rows)
                //    {
                //        sb.Append(" <li><a title=\"" + dr["Title"].ToString() + "\" href=\"SmallType.aspx?id=" + dr["ID"].ToString() + "\"><b>" + dr["PageUrl"].ToString() + "</b></a></li>");

                //        sb1.Append("<div class=\"index_sort_border\">");
                //        sb1.Append("<div class=\"title_block\" >● <a href=\"SmallType.aspx?id=" + dr["ID"].ToString() + "\">" + dr["PageUrl"].ToString() + " <strong>... 查看更多</a></strong></div>");
                //        sb1.Append(GetData(bll.GetModel(int.Parse(dr["ID"].ToString()))));
                //        sb1.Append("<div style=\"clear:both\"></div>");
                //        sb1.Append("<div class=\"title_block_bg_bottom\"></div>");
                //        sb1.Append("</div>");
                //    }
                //    sb.Append("   </ul>");
                //    sb.Append("</div>");
                //}




                ////最近更新
                //sb.Append("<div class=\"right_block\">");
                //sb.Append("<div class=\"right_block_title\">");
                //sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>最近更新</div>");
                //sb.Append("</div>");
                //sb.Append("<div class=\"right_block_content\">");
                //sb.Append("<ul>");

                //string s = bll.GetChannels(id).ToString();
                //if (s != "")
                //{
                //    DataTable dtzj = pll.GetList(15, " ClassId in (" + s + ")", " AddTime desc,Click desc").Tables[0];
                //    foreach (DataRow dr1 in dtzj.Rows)
                //    {
                //        sb.Append("<li>. <a href=\"DetailTW.aspx?id=" + dr1["ID"].ToString() + "\" title=\"" + dr1["Title"].ToString() + "/ " + dr1["AddTime"].ToString() + "\" target=\"_blank\">" + dr1["Title"].ToString() + "</a></li>");
                //    }
                //}
                //sb.Append(" </ul>");
                //sb.Append("</div>");
                //sb.Append("</div>  ");

                ////最热
                //sb.Append("<div class=\"right_block\">");
                //sb.Append("<div class=\"right_block_title\">");
                //sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>热点</div>");
                //sb.Append("</div>");
                //sb.Append("<div class=\"right_block_content\">");
                //sb.Append("<ul>");

                //s = bll.GetChannels(id).ToString();
                //if (s != "")
                //{
                //    DataTable dtzr = pll.GetList(15, " ClassId in (" + s + ")", " Click desc,AddTime desc").Tables[0];
                //    foreach (DataRow dr2 in dtzr.Rows)
                //    {
                //        sb.Append("<li>. <a href=\"DetailTW.aspx?id=" + dr2["ID"].ToString() + "\" title=\"" + dr2["Title"].ToString() + "/ " + dr2["Click"].ToString() + " Hits\" target=\"_blank\">" + dr2["Title"].ToString() + "</a></li>");
                //    }
                //}
                //sb.Append(" </ul>");
                //sb.Append("</div>");
                //sb.Append("</div>  ");


                #endregion

                sb.Append("<div class=\"type_menu_dao\">");
                sb.Append("<div style=\"background:url(images/daohang.jpg) no-repeat; width:280px; height:30px; margin-left:3px; line-height:30px; text-align:center; color:#FBF204; font-size:14px;\">");
                sb.Append("<b>" + typename + "</b></div>");
                sb.Append("<ul>");
                foreach (DataRow dr in dt.Rows)
                {
                    sb.Append(" <li><a title=\"" + dr["Title"].ToString() + "\" href=\"SmallType.aspx?id=" + dr["ID"].ToString() + "\"><b>" + dr["PageUrl"].ToString() + "</b></a></li>");

                    sb1.Append("<div class=\"index_sort_border\">");
                    sb1.Append("<div class=\"title_block\" >● <a href=\"SmallType.aspx?id=" + dr["ID"].ToString() + "\">" + dr["PageUrl"].ToString() + " <strong>... 查看更多</a></strong></div>");
                    sb1.Append(GetData(bll.GetModel(int.Parse(dr["ID"].ToString()))));
                    sb1.Append("<div style=\"clear:both\"></div>");
                    sb1.Append("<div class=\"title_block_bg_bottom\"></div>");
                    sb1.Append("</div>");
                }
                sb.Append("   </ul>");
                sb.Append("</div>");
            }

                string s = bll.GetChannels(id).ToString();
                if (s != "")
                {
                        dtzx = pll.GetList(15, " ClassId in (" + s + ")", " AddTime desc,Click desc").Tables[0];
                        dtrd = pll.GetList(15, " ClassId in (" + s + ")", " Click desc,AddTime desc").Tables[0];
                        if (dtzx.Rows.Count > 0)
                        {
                            urladd = "DetailTW.aspx";
                                sb.Append("<div class=\"right_block\">");
                                sb.Append("<div class=\"right_block_title\">");
                                sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>最近更新</div>");
                                sb.Append("</div>");
                                sb.Append("<div class=\"right_block_content\">");
                                sb.Append("<ul>");



                                foreach (DataRow dr1 in dtzx.Rows)
                                {
                                    string title = dr1["Title"].ToString();
                                    if (title.Length > 18)
                                    {
                                        title = title.Substring(0, 18) + "...";
                                    }
                                    sb.Append("<li>. <a href=\"/" + urladd + "?id=" + dr1["ID"].ToString() + "\" title=\"" + dr1["Title"].ToString() + "/ " + dr1["AddTime"].ToString() + "\" target=\"_blank\">" + title + "</a></li>");
                                }
                                sb.Append(" </ul>");
                                sb.Append("</div>");
                                sb.Append("</div>  ");
                            
                        }
                        else
                        {
                            dtzx = all.GetList(15, " ClassId in (" + s + ")", " AddTime desc,Click desc").Tables[0];
                            if (dtzx.Rows.Count > 0)
                            {
                                urladd = "DetailWB.aspx";
                                sb.Append("<div class=\"right_block\">");
                                sb.Append("<div class=\"right_block_title\">");
                                sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>最近更新</div>");
                                sb.Append("</div>");
                                sb.Append("<div class=\"right_block_content\">");
                                sb.Append("<ul>");



                                foreach (DataRow dr1 in dtzx.Rows)
                                {
                                    string title = dr1["Title"].ToString();
                                    if (title.Length > 18)
                                    {
                                        title = title.Substring(0, 18) + "...";
                                    }
                                    sb.Append("<li>. <a href=\"/" + urladd + "?id=" + dr1["ID"].ToString() + "\" title=\"" + dr1["Title"].ToString() + "/ " + dr1["AddTime"].ToString() + "\" target=\"_blank\">" + title + "</a></li>");
                                }
                                sb.Append(" </ul>");
                                sb.Append("</div>");
                                sb.Append("</div>  ");
                            }
                        }


                        if (dtrd.Rows.Count > 0)
                        {
                            urladd = "DetailTW.aspx";
                            sb.Append("<div class=\"right_block\">");
                            sb.Append("<div class=\"right_block_title\">");
                            sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>热点</div>");
                            sb.Append("</div>");
                            sb.Append("<div class=\"right_block_content\">");
                            sb.Append("<ul>");


                            foreach (DataRow dr2 in dtrd.Rows)
                            {
                                string title1 = dr2["Title"].ToString();
                                if (title1.Length > 18)
                                {
                                    title1 = title1.Substring(0, 18) + "...";
                                }
                                sb.Append("<li>. <a href=\"/" + urladd + "?id=" + dr2["ID"].ToString() + "\" title=\"" + dr2["Title"].ToString() + "/ " + dr2["Click"].ToString() + " Hits\" target=\"_blank\">" + title1 + "</a></li>");
                            }

                            sb.Append(" </ul>");
                            sb.Append("</div>");
                            sb.Append("</div>  ");
                        }
                        else
                        {
                            dtrd = all.GetList(15, " ClassId in (" + s + ")", " Click desc,AddTime desc").Tables[0];
                            if (dtrd.Rows.Count > 0)
                            {
                                urladd = "DetailWB.aspx";
                                sb.Append("<div class=\"right_block\">");
                                sb.Append("<div class=\"right_block_title\">");
                                sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>热点</div>");
                                sb.Append("</div>");
                                sb.Append("<div class=\"right_block_content\">");
                                sb.Append("<ul>");


                                foreach (DataRow dr2 in dtrd.Rows)
                                {
                                    string title1 = dr2["Title"].ToString();
                                    if (title1.Length > 18)
                                    {
                                        title1 = title1.Substring(0, 18) + "...";
                                    }
                                    sb.Append("<li>. <a href=\"/" + urladd + "?id=" + dr2["ID"].ToString() + "\" title=\"" + dr2["Title"].ToString() + "/ " + dr2["Click"].ToString() + " Hits\" target=\"_blank\">" + title1 + "</a></li>");
                                }

                                sb.Append(" </ul>");
                                sb.Append("</div>");
                                sb.Append("</div>  ");
                            }
                        }



                    
                }

                //if (urladd != string.Empty)
                //{





                //    //最近更新
                //    if (dtzx.Rows.Count > 0)
                //    {
                //        sb.Append("<div class=\"right_block\">");
                //        sb.Append("<div class=\"right_block_title\">");
                //        sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>最近更新</div>");
                //        sb.Append("</div>");
                //        sb.Append("<div class=\"right_block_content\">");
                //        sb.Append("<ul>");



                //        foreach (DataRow dr1 in dtzx.Rows)
                //        {
                //            string title = dr1["Title"].ToString();
                //            if (title.Length > 18)
                //            {
                //                title = title.Substring(0, 18) + "...";
                //            }
                //            sb.Append("<li>. <a href=\"/" + urladd + "?id=" + dr1["ID"].ToString() + "\" title=\"" + dr1["Title"].ToString() + "/ " + dr1["AddTime"].ToString() + "\" target=\"_blank\">" + title + "</a></li>");
                //        }
                //        sb.Append(" </ul>");
                //        sb.Append("</div>");
                //        sb.Append("</div>  ");
                //    }

                //    //最热
                //    if (dtrd.Rows.Count > 0)
                //    {
                //        sb.Append("<div class=\"right_block\">");
                //        sb.Append("<div class=\"right_block_title\">");
                //        sb.Append("<div class=\"left_block_title_text\"><strong>" + typename + "</strong>热点</div>");
                //        sb.Append("</div>");
                //        sb.Append("<div class=\"right_block_content\">");
                //        sb.Append("<ul>");


                //        foreach (DataRow dr2 in dtrd.Rows)
                //        {
                //            string title1 = dr2["Title"].ToString();
                //            if (title1.Length > 18)
                //            {
                //                title1 = title1.Substring(0, 18) + "...";
                //            }
                //            sb.Append("<li>. <a href=\"/" + urladd + "?id=" + dr2["ID"].ToString() + "\" title=\"" + dr2["Title"].ToString() + "/ " + dr2["Click"].ToString() + " Hits\" target=\"_blank\">" + title1 + "</a></li>");
                //        }

                //        sb.Append(" </ul>");
                //        sb.Append("</div>");
                //        sb.Append("</div>  ");
                //    }
                //}
            
                this.LiteraClassType.Text = sb.ToString();
                this.LiteralContent.Text = sb1.ToString();


                int nor = bll.GetModel(id).ParentId;
                sb2.Append(" <a href=\"Index.aspx\">网站首页</a> > ");
                sb2.Append(" <a href=\"BigType.aspx?id=" + nor + "\">" + bll.GetChannelTitle(nor) + "</a> > ");
                sb2.Append(" <strong>" + model.Title + "</strong> ");

                this.Literaldh.Text = sb2.ToString();




            
        }

        private StringBuilder GetData(LKCMS.Model.Channel model)
        {

            DataTable dt = new DataTable();
            LKCMS.BLL.Pictures pll = new LKCMS.BLL.Pictures();
            LKCMS.BLL.Article all = new LKCMS.BLL.Article();
            StringBuilder sb1 = new StringBuilder();
            switch (model.KindId)
            {
                case 0:
                    dt = all.GetList(8," ClassId=" + model.Id, "AddTime desc").Tables[0];

                    sb1.Append("<div class=\"type_text_case2\">");
                    sb1.Append("<ul>");
                    foreach (DataRow dr12 in dt.Rows)
                    {

                        sb1.Append("<li><a href=\"DetailWB.aspx?id=" + dr12["ID"].ToString() + "\" title=\"" + dr12["Title"].ToString() + "\" target=\"_blank\">" + dr12["Title"].ToString() + "</a> <span class=whitebot> - " + Convert.ToDateTime(dr12["AddTime"]).ToString("MM/dd/yyyy") + "</span></li> ");
                    }
                    sb1.Append("</ul>");
                    sb1.Append("</div>");
                    break;
                case 1:
                    dt = pll.GetList(12, " ClassId=" + model.Id, "SortId asc,AddTime desc").Tables[0];
                   
                    sb1.Append("<div id=\"three_pics\">");
                    sb1.Append("<ul>");
                    foreach (DataRow dr11 in dt.Rows)
                    {

                        sb1.Append("<li><a title=\"RMB " + Convert.ToDecimal(dr11["Price"]).ToString("f2") + "元/人 -" + dr11["Title"].ToString() + "\" href=\"DetailTW.aspx?id=" + dr11["ID"].ToString() + "\"><img width=\"146\" height=\"71\" alt=\"" + dr11["Title"].ToString() + "\" src=\"" + dr11["ImgUrl"].ToString() + "\" border=\"0\"><div>" + dr11["Title"].ToString() + "</div></a><div class=\"pic_price\">RMB " + Convert.ToDecimal(dr11["Price"]).ToString("f2") + "元/人</div></li> ");
                    }
                    sb1.Append("</ul>");
                    sb1.Append("</div>");
                    break;
                case -1:
                    break;
                default:
                    break;
            }

            return sb1;
        }
    }
}
